package myjava.overriding;

public class Root6 {

   public static void main(String[] args) {

      DogFactoy df = new DogFactoy();
      DogFactoyB4 dfb4 = new DogFactoyB4();

      df.get().bark();
      // boooooring
      ((Dog) dfb4.get()).bark();
   }
}

class Animal {

   public void live() {
      System.out.println("Animal lives");
   }
}

class Dog extends Animal {

   @Override
   public void live() {
      System.out.println("Dog lives");
   }

   public void bark() {
      System.out.println("bau bau!");
   }
}

class AnimalFactory {

   public Animal get() {
      return new Animal();
   }
}

class DogFactoy extends AnimalFactory {

   // as of java 1.5 you can change the return type of an overriding method
   // provided the retuned thing is a subclass of the one in the overridden method
   @Override
   public Dog get() {
      return new Dog();
   }
}

class DogFactoyB4 extends AnimalFactory {

   // before java 1.5
   @Override
   public Animal get() {
      return new Dog();
   }
}